home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_509 / multi_player / sources / pp_decrunch.s < prev    next >
Text File  |  1992-05-06  |  3KB  |  157 lines

  1. ;
  2. ; PowerPacker Decrunch assembler subroutine V1.1
  3. ;
  4. ; call as:
  5. ;    DecrunchBuffer (endcrun, buffer, efficiency);
  6. ; with:
  7. ;    endcrun   : UBYTE * just after last byte of crunched file
  8. ;    buffer    : UBYTE * to memory block to decrunch in
  9. ;    efficiency: Longword defining efficiency with wich file was crunched
  10. ;
  11. ; NOTE:
  12. ;    Decrunch a few bytes higher (safety margin) than the crunched file
  13. ;    to decrunch in the same memory space. (64 bytes suffice)
  14. ;
  15.  
  16.     XDEF _pp_DecrunchBuffer
  17.     XDEF _pp_DecrunchColor
  18.     XDEF _pp_CalcCheckSum
  19.     XDEF _pp_CalcPasskey
  20.     XDEF _pp_Decrypt
  21.  
  22. _pp_DecrunchBuffer:
  23.     move.l 4(a7),a0
  24.     move.l 8(a7),a1
  25.     move.l 12(a7),d0
  26.     movem.l d1-d7/a2-a6,-(a7)
  27.     bsr.s Decrunch
  28.     movem.l (a7)+,d1-d7/a2-a6
  29.     rts
  30. Decrunch:
  31.     lea myBitsTable(PC),a5
  32.     move.l d0,(a5)
  33.     move.l a1,a2
  34.     move.l -(a0),d5
  35.     moveq #0,d1
  36.     move.b d5,d1
  37.     lsr.l #8,d5
  38.     add.l d5,a1
  39.     move.l -(a0),d5
  40.     lsr.l d1,d5
  41.     move.b #32,d7
  42.     sub.b d1,d7
  43. LoopCheckCrunch:
  44.     bsr.s ReadBit
  45.     tst.b d1
  46.     bne.s CrunchedBytes
  47. NormalBytes:
  48.     moveq #0,d2
  49. Read2BitsRow:
  50.     moveq #2,d0
  51.     bsr.s ReadD1
  52.     add.w d1,d2
  53.     cmp.w #3,d1
  54.     beq.s Read2BitsRow
  55. ReadNormalByte:
  56.     move.w #8,d0
  57.     bsr.s ReadD1
  58.     move.b d1,-(a1)
  59.     dbf d2,ReadNormalByte
  60.     cmp.l a1,a2
  61.     bcs.s CrunchedBytes
  62.     rts
  63. CrunchedBytes:
  64.     moveq #2,d0
  65.     bsr.s ReadD1
  66.     moveq #0,d0
  67.     move.b (a5,d1.w),d0
  68.     move.l d0,d4
  69.     move.w d1,d2
  70.     addq.w #1,d2
  71.     cmp.w #4,d2
  72.     bne.s ReadOffset
  73.     bsr.s ReadBit
  74.     move.l d4,d0
  75.     tst.b d1
  76.     bne.s LongBlockOffset
  77.     moveq #7,d0
  78. LongBlockOffset:
  79.     bsr.s ReadD1
  80.     move.w d1,d3
  81. Read3BitsRow:
  82.     moveq #3,d0
  83.     bsr.s ReadD1
  84.     add.w d1,d2
  85.     cmp.w #7,d1
  86.     beq.s Read3BitsRow
  87.     bra.s DecrunchBlock
  88. ReadOffset:
  89.     bsr.s ReadD1
  90.     move.w d1,d3
  91. DecrunchBlock:
  92.     move.b (a1,d3.w),d0
  93.     move.b d0,-(a1)
  94.     dbf d2,DecrunchBlock
  95. EndOfLoop:
  96. _pp_DecrunchColor:
  97.     move.w a1,$dff1a2
  98.     cmp.l a1,a2
  99.     bcs.s LoopCheckCrunch
  100.     rts
  101. ReadBit:
  102.     moveq #1,d0
  103. ReadD1:
  104.     moveq #0,d1
  105.     subq.w #1,d0
  106. ReadBits:
  107.     lsr.l #1,d5
  108.     roxl.l #1,d1
  109.     subq.b #1,d7
  110.     bne.s No32Read
  111.     move.b #32,d7
  112.     move.l -(a0),d5
  113. No32Read:
  114.     dbf d0,ReadBits
  115.     rts
  116. myBitsTable:
  117.     dc.b $09,$0a,$0b,$0b
  118.  
  119. _pp_CalcCheckSum:
  120.     move.l 4(a7),a0
  121.     moveq #0,d0
  122.     moveq #0,d1
  123. sumloop:
  124.     move.b (a0)+,d1
  125.     beq.s exitasm
  126.     ror.w d1,d0
  127.     add.w d1,d0
  128.     bra.s sumloop
  129. _pp_CalcPasskey:
  130.     move.l 4(a7),a0
  131.     moveq #0,d0
  132.     moveq #0,d1
  133. keyloop:
  134.     move.b (a0)+,d1
  135.     beq.s exitasm
  136.     rol.l #1,d0
  137.     add.l d1,d0
  138.     swap d0
  139.     bra.s keyloop
  140. exitasm:
  141.     rts
  142. _pp_Decrypt:
  143.     move.l 4(a7),a0
  144.     move.l 8(a7),d1
  145.     move.l 12(a7),d0
  146.     move.l d2,-(a7)
  147.     addq.l #3,d1
  148.     lsr.l #2,d1
  149.     subq.l #1,d1
  150. encryptloop:
  151.     move.l (a0),d2
  152.     eor.l d0,d2
  153.     move.l d2,(a0)+
  154.     dbf d1,encryptloop
  155.     move.l (a7)+,d2
  156.     rts
  157.